    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPCell;

import java.io.FileOutputStream;
import java.io.FileNotFoundException;

import DBMS.DataBaseManager;
import com.itextpdf.text.Font;
import com.itextpdf.text.Rectangle;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;

public class ReportePreseleccion extends Reporte {

    int numPreselectos;
    int numAspirantes;
    int numNoPreselectos;
    int numInst[];
    int numInst2[];
    String nombreInst[];
    List preselectos;
    List noPreselectos;
    String path;

    public ReportePreseleccion() {
    }

    public List getNoPreselectos() {
        return noPreselectos;
    }

    public void setNoPreselectos(List noPreselectos) {
        this.noPreselectos = noPreselectos;
        this.preselectos = null;
    }

    public int[] getNumInst2() {
        return numInst2;
    }

    public void setNumInst2(int[] numInst2) {
        this.numInst2 = numInst2;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String[] getNombreInst() {
        return nombreInst;
    }

    public void setNombreInst(String[] nombreInst) {
        this.nombreInst = nombreInst;
    }

    public int getNumAspirantes() {
        return numAspirantes;
    }

    public void setNumAspirantes(int numAspirantes) {
        this.numAspirantes = numAspirantes;
    }

    public int[] getNumInst() {
        return numInst;
    }

    public void setNumInst(int[] numInst) {
        this.numInst = numInst;
    }

    public int getNumNoPreselectos() {
        return numNoPreselectos;
    }

    public void setNumNoPreselectos(int numNoPreselectos) {
        this.numNoPreselectos = numNoPreselectos;
    }

    public int getNumPreselectos() {
        return numPreselectos;
    }

    public void setNumPreselectos(int numPreselectos) {
        this.numPreselectos = numPreselectos;
    }

    public List getPreselectos() {
        return preselectos;
    }

    public void setPreselectos(List preselectos) {
        this.noPreselectos = null;
        this.preselectos = preselectos;
    }

    public void generar(String path) throws FileNotFoundException {
        System.out.println("Se va a intentar crear el reporte en " + path);
        FileOutputStream f = new FileOutputStream(path);
        Document document = new Document();

        try {
            PdfWriter writer = PdfWriter.getInstance(document, f);


            Rectangle rct = new Rectangle(36, 54, 559, 788);
            //Definimos un nombre y un tamaño para el PageBox los nombres posibles son: “crop”, “trim”, “art” and “bleed”.
            writer.setBoxSize("art", rct);
            HeaderFooter event = new HeaderFooter(this.getId(), this.getNumAutenticacion());
            writer.setPageEvent(event);
            document.open();
            //Encabezado
            Font fuente = new Font(Font.getFamily("ARIAL"), 16, Font.BOLD);
            DateFormat dates = new SimpleDateFormat("dd/MM/yyyy");
            Date date = new Date();
            String encabezado = "\nCaracas " + dates.format(date) + "\n"
                    + "Programa de Igualdad de Oportunidades \n"
                    + "Reporte de PIO Nro." + this.getId() + "\n";
            Paragraph pa = new Paragraph(encabezado, fuente);
            pa.setSpacingBefore(20);
            pa.setSpacingAfter(10);
            pa.setIndentationLeft(50);
            document.add(pa);
            // Datos Basico
            String s = "Datos Generales:";
            Paragraph p = new Paragraph(s);
            p.setSpacingBefore(20);
            p.setSpacingAfter(10);
            p.setIndentationLeft(50);
            document.add(p);
            PdfPTable table = new PdfPTable(2); // 3 columns.
            s = "Aspirantes Seleccionados: " + numPreselectos;
            PdfPCell cell1 = new PdfPCell(new Paragraph(s));
            s = "Aspirantes No Seleccionados: " + numNoPreselectos;
            PdfPCell cell2 = new PdfPCell(new Paragraph(s));
            table.addCell(cell1);
            table.addCell(cell2);
            document.add(table);

            // Selecionados por institucio
            s = "Aspirantes por Instituciones:";
            p = new Paragraph(s);
            p.setSpacingBefore(20);
            p.setSpacingAfter(10);
            p.setIndentationLeft(50);
            document.add(p);
            table = new PdfPTable(3);
            float[] columnWidths = {2f, 1f, 1f};
            table.setWidths(columnWidths);
            s = "Institucion";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            s = "Seleccionados";
            cell2 = new PdfPCell(new Paragraph(s));
            cell2.setBorder(PdfPCell.NO_BORDER);
            s = "No Seleccionados";
            PdfPCell cell3 = new PdfPCell(new Paragraph(s));
            cell3.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            table.addCell(cell2);
            table.addCell(cell3);
            for (int i = 0; i != numInst.length; i++) {
                cell1 = new PdfPCell(new Paragraph(nombreInst[i]));
                s = "" + numInst[i];
                cell2 = new PdfPCell(new Paragraph(s));
                s = "" + numInst2[i];
                cell3 = new PdfPCell(new Paragraph(s));
                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
            }
            document.add(table);

            // Preseleccionados
            Iterator i;
            if (preselectos != null) {
                s = "Preseleccionados:";
                i = preselectos.iterator();
            } else {
                s = "No Preseleccionados:";
                i = noPreselectos.iterator();
            }
            p = new Paragraph(s);
            p.setSpacingBefore(20);
            p.setSpacingAfter(10);
            p.setIndentationLeft(50);
            document.add(p);
            table = new PdfPTable(3);
//            table.setWidthPercentage(100);
            s = "Cedula";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Nombres";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Apellidos";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            while (i.hasNext()) {
                s = i.next().toString();
                System.out.println(s + "1");
                cell1 = new PdfPCell(new Paragraph(s));
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell1);
            }
            document.add(table);
            document.close();
            f.flush();
            f.close();
        } catch (Exception e) {
            //imprimimos los errores
            System.err.println(e);
            e.printStackTrace();
        }
    }
}